//config-overrides.js
const {
    override,
    fixBabelImports,
    addDecoratorsLegacy,
    addWebpackPlugin,
    addWebpackModuleRule,
    adjustStyleLoaders,
    disableEsLint,
    addWebpackAlias,
    // addWebpackExternals,
} = require('customize-cra');

const moment = require("moment");
const path = require("path");
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const paths = require('react-scripts/config/paths')
paths.appBuild = path.join(path.dirname(paths.appBuild), 'dist', process.env.REACT_APP_OUTDIR)

module.exports = override(
    // 禁用eslint检查
    disableEsLint(),

    addWebpackAlias({
        "@": path.resolve(__dirname, "./src"),
    }),
    // addWebpackExternals(

    // ),
    // 设置打包时去掉console
    process.env.NODE_ENV === 'production' && addWebpackPlugin(new UglifyJsPlugin({
        uglifyOptions: {
            compress: {
                drop_debugger: true,
                drop_console: true
            }
        },
    })),
    // 处理scss和less互相使用
    addWebpackModuleRule(
        {
            test: /\.scss$/,
            issuer: /\.less$/,
            use: {
                loader: "./sassVarsToLess.js" // Change path if necessary
            }
        }
    ),
    //scss全局变量
    adjustStyleLoaders(rule => {
        if (rule.test.toString().includes("scss")) {
            rule.use.push({
                loader: require.resolve("sass-resources-loader"),
                options: {
                    resources: "./src/assets/css/theme.scss"
                }
            });
        }
    }),
    // antd样式
    fixBabelImports('antd', {
        libraryName: 'antd',
        style: 'css',
    }),
    //mobx
    addDecoratorsLegacy()
);